#include "ObjFac.h"
#include "Hero.h"
#include "Enemy.h"
#include "Boss.h"
#include "Element.h"
#include "ObjActor.h"
#include "Player/AnimPlayerFac.h"
#include "GameRes/AnimMgr.h"
#include "Player/LoopFac.h"
#include <memory>
namespace LTGame
{

	XOBJ* ObjFac::createByDat(short* dat , int ai)
	{
		XOBJ* obj = NULL;
		bool isDirectDraw = true;
		switch (ai)
		{
		case CLASS_ID_HERO: 
			obj = new CHero(); 
			break;
		case CLASS_ID_ENEMY: obj = new CEnemy(); isDirectDraw = false; break;
		case CLASS_ID_OBJ: obj = new CEnemy(); isDirectDraw = false; break;
		case CLASS_ID_BOSS: obj = new CBoss(); isDirectDraw = false; break;
		case CLASS_ID_SCRIPT:
		case CLASS_ID_SYSTEM:
		case CLASS_ID_SHOW: obj = new XOBJ(); isDirectDraw = false; break;
		case CLASS_ID_CAMERA: obj = new CCameraCtrl(); break;
		default:
			return NULL;
		}

		obj->m_flag	= dat[COBJ_DAT_FLAG];
		obj->m_cur_x	= dat[COBJ_DAT_P_X];
		obj->m_cur_y	= dat[COBJ_DAT_P_Y];
		obj->m_aiid	= ai;
		obj->m_dat	= dat;
		obj->isInScriptRunning = false;
		obj->startSubScriptID = 0;
		obj->cur_state = 0;

		if ( obj->m_dat[COBJ_DAT_ACTION] >= 0 && obj->m_dat[COBJ_DAT_ANIID] >= 0 )
		{
			if (obj->m_player!=NULL)
			{
				CC_SAFE_DELETE(obj->m_player);
			}
			auto_ptr<AnimPlayerFac> fac(new LoopFac());
			obj->m_player = fac->CreatePlayer(obj->m_dat[COBJ_DAT_ANIID], obj->m_dat[COBJ_DAT_ACTION], isDirectDraw);
		}
		obj->initialize();
		
		return obj;
	}

}